15 Replies Latest reply on Feb 2, 2017 3:25 PM by gregor

    How do I know if AF server is down?

    ChaoXu

      I are implementing an window service application using AFDataPipe, signup attributes and then get AFDataPipeEvent. How I don know if PI AF Server is down after the application is already running,  so that I can send out email notification?

        • Re: How do I know if AF server is down?
          Roger Palmen

          It would depend on the tooling you have available. Of course you cannot use AF and Notifications....

          If you have an IT monitoring tool, i would suggest to try and read data from AF. You can pick some functional attribute, or e.g. try to read the time: PISystem.ServerTime Property. You can make that call through AFSDK or PowerShell. There are plenty of tools around if you don't want to build something yourselves. Otherwise, you can go a long way with some powershell scripting and windows task scheduler.

          • Re: How do I know if AF server is down?
            rsun

            I believe you can just check if the PI AF Application Service is running or not.

            • Re: How do I know if AF server is down?
              daneoverfield

              Our TopView Alarm and Notification software will be able to do this in the next release (testing now, planned release sometime Feb 2017)

              Currently we have TopView PI which uses the PISDK to monitor PI tags but the next release includes TopView PIAF which uses the AFSDK for monitoring both PI tags and AF attributes.

              Part of our real-time monitoring engine includes knowing if we are connected to the AF Server. You can configure notifications when the connection fails and another when it resumes. Out-of-the-box notifications include email, sms (cellular modems), and voice callout (TAPI or VOIP). Lots of other features too.

              • Re: How do I know if AF server is down?
                nkrstic@kockw.com

                Why not use the OS?

                SC command check the service is running or not, you can also have a PI display ( PI overview ) kind of display to see what is up or down.

                1 of 1 people found this helpful
                • Re: How do I know if AF server is down?
                  Rhys Kirk

                  Use PI Perfmon to scan the Performance Counter for "PI AF Server => Health". Use a fairly fast scan to capture it. See here as an example: Need information on AF service health PI Point

                  1 of 1 people found this helpful
                  • Re: How do I know if AF server is down?
                    gregor

                    Hello Chao,

                     

                    The way you've phrased your question leaves room for interpretation what you are looking for. While I agree to everything that was said so far, I like to suggest the approach to handle this client side. I am using the following AF SDK code:

                     

                    using System;
                    using OSIsoft.AF;
                    using System.Threading;
                    namespace PIS16035
                    {
                        class Program
                        {
                            static void Main(string[] args)
                            {
                                string afServer = "AFServer";
                                int retryDelay = 1000;
                                PISystem piSystem = new PISystems()[afServer];
                                do
                                {
                                    if (Console.KeyAvailable) { break; }
                                    try
                                    {
                                        Console.WriteLine("Not connected. Attempting connect .. ");
                                        piSystem.Connect();
                                    }
                                    catch (Exception ex)
                                    {
                                        Console.WriteLine("Exception: {0} \r\n{1}", ex.HResult, ex.Message);
                                        Console.Write("Inner Exception: {0} \r\n{1}", ex.InnerException.HResult, ex.InnerException.Message);
                                        Console.WriteLine();
                                        Console.WriteLine("Will reattempt in {0} milliseconds", retryDelay);
                                        Thread.Sleep(retryDelay);
                                        Console.WriteLine();
                                    }
                                } while (!piSystem.ConnectionInfo.IsConnected);
                                Console.WriteLine("Connected :-)");
                                Console.Write("Press any key to quit .. ");
                                Console.ReadKey();
                            }
                        }
                    }
                    

                     

                    With the PI AF Application Service in stopped state, the output looks as follows:

                    With the PI AF Server Application Service running but the belonging SQL Server instance stopped, the output is different:

                    With both services running, the connection attempt should succeed:

                    Because PI AF Server requires the belonging SQL Instance but not the other way around, testing other possible combinations doesn't make much sense to me. One could possibly run a test with the PI AF Server host shut down or disconnected from the network but I expect the result to be similar to taking the PI AF Application Service down (1st screenshot).

                     

                    I conclude, one can distinguish 2 reasons for PI AF Server being unavailable based on InnerException.HResult:

                     

                    -2146233087 => PI AF Application Service is down or PI AF Server host is unavailable

                    -2146233079 => PI SQL Instance hosting the PIFD Database is down

                    5 of 5 people found this helpful
                    • Re: How do I know if AF server is down?
                      pthivierge

                      Hello Chao,

                      Another option is the PI Connector For System Health

                       

                      From the User Guide:

                      PI Connector for PI System Health records the health statistics of the local PI System and stores them in a PI System. The connector models an installation by creating the AF elements in PI Asset Framework (PI AF) and PI points in PI Data Archive, then populating the AF elements and PI points with data sent from the source. This connector will archive health information of the local PI System in the following areas:

                       

                      • PI AF Server
                      • PI Data Archive
                      • PI Analysis Service

                       

                      PI Connector for PI System Health uses Windows performance counters and AF SDK to receive data from the local PI System.

                      ...

                      So basically, you could read (or use a data pipe) the PI Tag Associated with the Windows performance counter that corresponds to the AF Service you want to monitor, and trigger your mail if the value indicate that the service has stopped.

                      This assumes that the PI Data Archive is running though.

                       

                      A good way to see if a process is running is to check it's private bytes and Elapsed Time performance counters:

                      Private Bytes: Private Bytes is the current size, in bytes, of memory that this process has allocated that cannot be shared with other processes.  If not updating, can mean that the process is hang.

                      Elapsed Time: The total elapsed time, in seconds, that this process has been running.  If not updating, the process is not running.

                       

                      Another option is to install the PI Performance Monitor interface on each node where you need to collect performance counter data:

                      • Create an instance of the PI Performance Monitor interface on each node where you installed the PI Performance Monitor Interface.  Use a distinct PointSource for  each interface instance.

                      • Create Performance Monitor tags in the PI Data Archive.  Use the Point source to determine which interface will load which tags.  I am attaching an excel file to propose what tags should be created.  You can also use the PI SMT Plug-in IT Points, performance counters to create the required tags.  If you do, I recommend to use PI SMT on each node you want to create tags for because remotely reading performance counters can be difficult.  

                      • Start the interfaces, check the list of created tags to make sure they are getting updated and data is being collected.

                       

                      And finally, you can have a look on this thread: System Performance Dashboard

                      There are monitoring views proposed in case you'd like to monitor your PI System graphically.

                       

                      Hope this helps,

                        • Re: How do I know if AF server is down?
                          gregor

                          Hi Patrice,

                           

                          PI Connectors are working Asset centric. I doubt the PI Connector for PI System Health will be able to update its data items (underlying PI Points) when the AF Server is down or unreachable except one is using the Connector to monitor a "foreign" PI System.

                           

                          The PI Connector for PI System Health collects health information in many areas and might be kind of an overkill - at least for just this use case.

                            • Re: How do I know if AF server is down?
                              pthivierge

                              Hello Gregor,

                               

                              Our connectors do keep a configuration cache.  So data collection will continue in case there is an issue with the service.

                               

                              I thought this might be a good alternative option this is why I have listed it here as well, for completeness of the question.

                                • Re: How do I know if AF server is down?
                                  gregor

                                  Hi Patrice,

                                  Our connectors do keep a configuration cache. So data collection will continue in case there is an issue with the service.

                                  That's a cool feature! I really wasn't aware and am happy that I learned something new to me!

                                  I thought this might be a good alternative option this is why I have listed it here as well, for completeness of the question.

                                  I agree. For completeness reasons when talking about collecting Performance Counter data, the PI Connector for PI System Health should be listed as one of the options.