PI AF was released last week along with a new version AF SDK (2.10.0.8628), so let me show you a feature that has been long requested by the community and that it's now available for you: the AFSession structure. This structure is used to represent a session on the AF Server and it exposes the following members:
Public Property | Description |
---|---|
AuthenticationType | The authentication type of the account which made the connection. |
ClientHost | The IP address of the client host which made the connection. |
ClientPort | The port number of the client host which made the connection. |
EndTime | The end time of the connection. |
GracefulTermination | A boolean that indicates if the end time was logged for graceful client termination. |
StartTime | The start time of the connection. |
UserName | The username of the account which made the connection. |
In order to get session information of a given PI System, the PISystem class now exposes a function called GetSessions(AFTime? startTime, AFTime? endTime, AFSortOrder sortOrder, int startIndex, int maxCount) and it returns an array of AFSessions. The AFSortOrder is an enumeration defining whether you want the startTime to be ascending or descending. Note that you can specify AFTime.MaxValue at the endTime to search only sessions which are still open.
From the documentation's remarks: The returned session data can be used to determine information about clients that are connected to the server. This information can be used to identify active clients. Then from the client machine, you can use the GetClientRpcMetrics() (for AF Server) method to determine what calls the clients are making to the server. Session information is not replicated in PI AF Collective environments. In these setups, make sure you connect to the member you want to retrieve session info from.
Shall we see it in action? The code I'm using is very simple:
var piSystem = (new PISystems()).DefaultPISystem; var sessions = piSystem.GetSessions(new AFTime("*-1d"), null, AFSortOrder.Descending); foreach (var session in sessions) { Console.WriteLine($"---- {session.ClientHost}:{session.ClientPort} ----"); Console.WriteLine($"Username: {session.UserName}"); Console.WriteLine($"Start time: {session.StartTime}"); Console.WriteLine($"End time: {session.EndTime}"); Console.WriteLine($"Graceful: {session.GracefulTermination}"); Console.WriteLine(); }
A cropped version of the result can be seen below:
---- 10.10.10.10:51582 ----
Username: OSI\rborges
Start time: 07/02/18 13:18:54
End time:
Graceful:
---- 10.10.10.10:62307 ----
Username: OSI\rborges
Start time: 07/02/18 13:06:36
End time: 07/02/18 13:11:51
Graceful: True
---- 10.10.10.10:62305 ----
Username: OSI\rborges
Start time: 07/02/18 13:06:17
End time: 07/02/18 13:06:19
Graceful: True
As you can see, now we can easily monitor sessions in your PI System. Share your thoughts about it in the comments and how you are planning on using it.
Happy coding!
Reference:
Rick's post on how to use metrics with AF SDK.
This was added as requested by many customers. I don't know their intentions, although it would be interesting to hear from others on how they plan on using this. Putting on my old AF Admin Hat, there are many uses I could see:
Show me list of users currently connected to the requested AF Server. Maybe I want to perform some maintenance on the host, and I want to notify others to disconnect gracefully rather than me rudely bumping them off without warning.
Show me a list of stale connections. Granted this means you must define staleness. Is 4 hours too short? What about 8 hours? Give me a list of users who have been connected more than 8 hours. It's Monday morning and I see Bob has been connected since Friday, but Bob is on vacation this week! I can pretty much assume this is a dead connection.
Show me a list of users who log in from multiple hosts.
For a given day, show me a count of how many ungraceful disconnects have occurred. Maybe show me top 3 users with ungraceful disconnects. Sit with them to watch what they do. There may be a training opportunity to show them the proper way to exit.
Show me a list of users who connect the most frequent or who are logged on the most. These are my heavy users. Or back when I worked at a plant, I would have a VIP list of users: the Plant Manager, Operations Director, Engineering Director, etc. I would monitor their usage (frequency, time of day, duration, etc.) to see patterns and anticipate questions.